package com.example.sunmiv1.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.ClassificationBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ClassificationAdapter extends BaseAdapter {

    private Context context;
    private List<ClassificationBean.GoodscateBean> list;
    ViewHolder viewHolder;

    public ClassificationAdapter(Context context, List<ClassificationBean.GoodscateBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.classification_adapter, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.classificationAdapterName.setText(list.get(position).getClass_name());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.classification_adapter_name)
        TextView classificationAdapterName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
